# coding=utf-8

import pandas as pd
import pymysql

from config import *


class ReadMaria(object):
    def get_data(self, sql):

        conn = pymysql.connect(host=MYSQL_HOST, port=MYSQL_PORT, user=MYSQL_USER, passwd=MYSQL_PASSWD, db=MYSQL_DBNAME,
                               charset='utf8')
        try:
            data = pd.read_sql(sql, conn)
            return data
        finally:
            conn.close()

    def main(self):
        date_list = ['2017-03-26', '2017-03-27', '2017-03-28', '2017-03-29', '2017-03-30',
                     '2017-03-31', '2017-04-01', '2017-04-02', '2017-04-03', '2017-04-04']
        list_platform = ['战旗', '熊猫', '斗鱼']
        for datesw in date_list:
            for platfromsw in list_platform:
                sql = "SELECT * FROM desc_rooms where date='{date}' AND platform='{platform}'".format(date=datesw,
                                                                                                      platform=platfromsw)
                data_csv = self.get_data(sql)
                # print(data_csv['hour'].value_counts())
                data = data_csv['hour'].value_counts()
                if len(data) != 24:
                    print('________'+datesw + platfromsw)
                    print()
                    print(data.index)
                    print()
                # print(len(data))
                # print(type(data))
                # data_csv.to_csv(
                #     "C:\\Users\\东旭\\Desktop\\最后的任务\\数据源\\{date}{platform}.csv".format(date=datesw, platform=platfromsw),
                #     index=False)
                # return


if __name__ == '__main__':
    RMaria = ReadMaria()
    RMaria.main()
